﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Helper.Controls">
    <Style x:Key="{x:Type ResizeGrip}"
       TargetType="{x:Type ResizeGrip}">
        <Setter Property="OverridesDefaultStyle"
          Value="true" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ResizeGrip}">
                    <Border Background="Transparent"
                SnapsToDevicePixels="True"
                Width="16"
                Height="16">
                        <Rectangle Margin="2">
                            <Rectangle.Fill>
                                <DrawingBrush Viewport="0,0,4,4"
                            ViewportUnits="Absolute"
                            Viewbox="0,0,8,8"
                            ViewboxUnits="Absolute"
                            TileMode="Tile">
                                    <DrawingBrush.Drawing>
                                        <DrawingGroup>
                                            <DrawingGroup.Children>
                                                <GeometryDrawing Brush="#FFE8EDF9"
                                       Geometry="M 4 4 L 4 8 L 
                                                 8 8 L 8 4 z" />
                                            </DrawingGroup.Children>
                                        </DrawingGroup>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

    <Style x:Key="SystemButton" TargetType="Button">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Height" Value="34"/>
        <Setter Property="Foreground" Value="{DynamicResource WhiteBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Border Name="Chrome"
                                Background="{TemplateBinding Background}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                SnapsToDevicePixels="true">
                        <ContentPresenter Margin="{TemplateBinding Padding}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="{DynamicResource ButtonTextHover}"/>
            </Trigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="false">
                <Setter Property="Foreground" Value="{DynamicResource ButtonTextDisabled}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    

    <Style x:Key="{x:Type local:CustomWindow}"
       TargetType="{x:Type local:CustomWindow}">
        <Setter Property="SnapsToDevicePixels"
          Value="true" />
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}"/>
        <Setter Property="WindowChrome.WindowChrome">
            <Setter.Value>
                <WindowChrome
            ResizeBorderThickness="6"
            CornerRadius="0"
            GlassFrameThickness="0">
                </WindowChrome>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type  local:CustomWindow}">
                    <Border BorderBrush="{DynamicResource WindowBorder}" BorderThickness="1">
                        <Grid>
                            
                            <Grid.Background>
                                <SolidColorBrush Color="{DynamicResource WindowBackgroundColor}"/>
                            </Grid.Background>
                            
                            <AdornerDecorator>
                                <ContentPresenter />
                            </AdornerDecorator>

                            <StackPanel Margin="0" WindowChrome.IsHitTestVisibleInChrome="True" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top">
                                <!--Minimize-->
                                <Button 
                            IsTabStop="False"
                                Width="34"
                                MaxHeight="34"
                                Command="{Binding Source={x:Static SystemCommands.MinimizeWindowCommand}}" 
                                Style="{StaticResource SystemButton}"
                                Visibility="{TemplateBinding ShowMinimize,
                                Converter={StaticResource BooleanToVisibilityConverter}}"
                                ToolTip="Minimize">
                                    <Path Data="F1M0,6L0,9 9,9 9,6 0,6z"
                                  SnapsToDevicePixels="True"
                                  Fill="{TemplateBinding Foreground}" />
                                </Button>
                                <!--Maximize-->
                                <Button
                                IsTabStop="False"
                                Width="34"
                                MaxHeight="34"
                                Command="{Binding Source={x:Static SystemCommands.MaximizeWindowCommand}}" 
                                Style="{StaticResource SystemButton}"
                                Visibility="{TemplateBinding ShowMaximize,
                                Converter={StaticResource BooleanToVisibilityConverter}}"
                            
                                ToolTip="Maximize">
                                    <Path SnapsToDevicePixels="True"
                                      Data="F1M0,0L0,9 9,9 9,0 0,0 0,3 8,3 8,8 1,8 1,3z"
                                      Fill="{TemplateBinding Foreground}" />
                                </Button>
                                <!--Restore-->
                                <Button
                                IsTabStop="False"
                                Width="34"
                                MaxHeight="34"
                                Command="{Binding Source={x:Static SystemCommands.RestoreWindowCommand}}" 
                                Style="{StaticResource SystemButton}"
                                Visibility="{TemplateBinding ShowRestore, 
                                Converter={StaticResource BooleanToVisibilityConverter}}"
                                ToolTip="Restore">
                                    <Path SnapsToDevicePixels="True"
                                      Data="F1M0,10L0,3 3,3 3,0 10,0 10,2 4,2 4,3 7,3 7,6 6,6 6,5 1,5 1,10z M1,10L7,10 7,7 10,7 10,2 9,2 9,6 6,6 6,9 1,9z"
                                      Fill="{TemplateBinding Foreground}" />
                                </Button>
                                <!--Close-->
                                <Button 
                                IsTabStop="False"
                                Width="34"
                                MaxHeight="34"
                                Command="{Binding Source={x:Static SystemCommands.CloseWindowCommand}}"
                                ToolTip="Close">
                                    <Path Data="F1M0,0L2,0 5,3 8,0 10,0 6,4 10,8 8,8 5,5 2,8 0,8 4,4 0,0z"
                                  SnapsToDevicePixels="True"
                                  Fill="{TemplateBinding Foreground}" />
                                    <Button.Style>
                                        <Style TargetType="Button" BasedOn="{StaticResource SystemButton}">
                                            <Style.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter Property="Background" Value="OrangeRed"/>
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Button.Style>
                                </Button>
                            </StackPanel>

                            <ResizeGrip x:Name="WindowResizeGrip"
                      HorizontalAlignment="Right"
                      VerticalAlignment="Bottom"
                      Visibility="Collapsed"
                      IsTabStop="false" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ResizeMode"
                   Value="CanResizeWithGrip">
                            <Setter TargetName="WindowResizeGrip"
                    Property="Visibility"
                    Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        
    </Style>
</ResourceDictionary>